﻿using System;
using Model;

namespace BusinessObject
{
    public class ProjectBO : Repository<Project>
    {
        #region Singleton

        private static readonly ProjectBO _instance = new ProjectBO();

        /// <summary>
        /// Instância do objeto singleton.
        /// </summary>
        public static ProjectBO Instance
        {
            get { return _instance; }
        }

        private ProjectBO() { }

        #endregion Singleton

        public Project InsertProject(string name, DateTime startDate, DateTime endDate, string description, User user)
        {
            try
            {
                Project projeto = new Project();
                projeto.Nome = name;
                projeto.DataInicio = startDate;
                projeto.DataFim = endDate;
                projeto.Descricao = description;

                ProjectBO.Instance.Save(projeto);
                ProjectUserBO.Instance.insertProjectUser(user.Id, projeto.Id, -1);

                return projeto;
            }
            catch
            {
                return null;
            }
        }

        public Project GetProjectByID(int id)
        {
            return base.GetById(id);
        }
    }
}